package com.example.speeddating.service.impl;

import com.example.speeddating.constants.TaoHuaConstant;
import com.example.speeddating.entity.Visitor;
import com.example.speeddating.mapper.TaohuaDetailMapper;
import com.example.speeddating.mapper.VisitorMapper;
import com.example.speeddating.service.TaohuaDetailService;
import com.example.speeddating.service.VisitorService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 *
 * @author tina
 * @since 2023-07-14 10:33:47
 */
@Service
public class VisitorServiceImpl extends ServiceImpl<VisitorMapper, Visitor> implements VisitorService {

    @Autowired
    private VisitorMapper visitorMapper;

    @Autowired
    private TaohuaDetailService taohuaDetailService;

    @Override
    public int batchUpdateVistors(Long userId) {
        return visitorMapper.batchUpdateVistors(userId);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public void addVisitor(Visitor visitor) {
        visitorMapper.insert(visitor);
    }

    @Override
    public void unLockVistors(Visitor visitor,Long userId) {
        visitorMapper.updateById(visitor);
        //扣除桃花
        taohuaDetailService.insertTaohuaDetail(TaoHuaConstant.Type_8,userId);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public void deleteVisitor(Long id, Long userId) {
        visitorMapper.deleteById(id);
        //扣除桃花
        taohuaDetailService.insertTaohuaDetail(TaoHuaConstant.Type_9,userId);
    }
}
